//
//  XYClassfyCell.swift
//  XYReadBook
//
//  Created by fox on 2017/9/6.
//  Copyright © 2017年 tsaievan. All rights reserved.
//

import UIKit


/// 分类cell
/// 现在比较习惯这种套路
class XYClassfyCell: UICollectionViewCell {
    
    var titleLab = UILabel()
    var countLab = UILabel()
    var model:Male? {
        didSet {
            if let model = model {
                titleLab.text = model.name
                countLab.text = String.init(format: "%d 本", model.bookCount)
            }
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    
    func setupUI() {
        
        contentView.addSubview(titleLab)
        contentView.addSubview(countLab)
        titleLab.font = UIFont.systemFont(ofSize: 20)
        titleLab.textAlignment = .center
        titleLab.textColor = UIColor.black
        countLab.font = UIFont.systemFont(ofSize: 14)
        countLab.textColor = UIColor.black
        countLab.textAlignment = .center
    }
    
    
    /// 用约束布局的话,不不敢确定约束会在什么时候生效.不过约束必然经经过大量的计算,才会转成frame,此方法在布局的时候会调用
    override func layoutSubviews() {
        super.layoutSubviews()
        
        titleLab.frame = CGRect.init(x: 0, y: 12, width: self.width, height: 18)
        countLab.frame = CGRect.init(x:0, y: titleLab.frame.maxY, width: contentView.width, height: 18)
    }
    
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}
